package com.wlj.security.core.validate.code.config;

import com.wlj.security.core.properties.WljSecurityProperties;
import com.wlj.security.core.validate.code.ValidateCodeGenerator;
import com.wlj.security.core.validate.code.image.ImageValidateCodeGenerator;
import com.wlj.security.core.validate.code.sms.DefaultSmsCodeSender;
import com.wlj.security.core.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private WljSecurityProperties wljSecurityProperties;



    /**
     * spring在初始化下面的bean之前会在容器里找是不是已经有叫imageCodeGenerator的bean了
     * 若有则使用已有的bean作为"imageCodeGenerator"而不是下面的
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator(){
        ImageValidateCodeGenerator imageCodeGenerator = new ImageValidateCodeGenerator();
        imageCodeGenerator.setWljSecurityProperties(wljSecurityProperties);
        return imageCodeGenerator;
    }

    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender(){
        return new DefaultSmsCodeSender();
    }



}
